import*as e from"../../../../core/common/common.js";import*as t from"../../../../core/host/host.js";import*as n from"../../../../core/i18n/i18n.js";import*as i from"../../../../core/platform/platform.js";import*as o from"../../../../core/sdk/sdk.js";import*as r from"../../../../models/bindings/bindings.js";import*as a from"../../legacy.js";import*as s from"../../../../models/breakpoints/breakpoints.js";import*as c from"../../../../models/text_utils/text_utils.js";import*as l from"../../../../models/workspace/workspace.js";const d=new CSSStyleSheet;d.replaceSync(".image-preview-container{background:transparent;text-align:center;border-spacing:0}.image-preview-container img{margin:6px 0;max-width:100px;max-height:100px;background-image:var(--image-file-checker);user-select:text;vertical-align:top;-webkit-user-drag:auto}.image-container{padding:0}.image-container > div{min-height:50px;display:flex;align-items:center;justify-content:center;cursor:pointer}.image-preview-container .row{line-height:1.2;vertical-align:baseline}.image-preview-container .title{padding-right:0.5em;text-align:right;color:var(--color-text-secondary);white-space:nowrap}.image-preview-container .description{white-space:nowrap;text-align:left;color:var(--color-text-primary)}.image-preview-container .description-link{max-width:20em}.image-preview-container .source-link{white-space:normal;word-break:break-all;color:var(--color-link);cursor:pointer}\n/*# sourceURL=imagePreview.css */\n");const u={unknownSource:"unknown source",imageFromS:"Image from {PH1}",fileSize:"File size:",intrinsicSize:"Intrinsic size:",renderedSize:"Rendered size:",currentSource:"Current source:",renderedAspectRatio:"Rendered aspect ratio:",intrinsicAspectRatio:"Intrinsic aspect ratio:"},p=n.i18n.registerUIStrings("ui/legacy/components/utils/ImagePreview.ts",u),g=n.i18n.getLocalizedString.bind(void 0,p);function m(t){return null!==t&&t.resourceType()===e.ResourceType.resourceTypes.Image}var h=Object.freeze({__proto__:null,ImagePreview:class{static async build(e,n,r,a={precomputedFeatures:void 0,imageAltText:void 0}){const{precomputedFeatures:s,imageAltText:c}=a,l=e.model(o.ResourceTreeModel.ResourceTreeModel);if(!l)return null;let p=l.resourceForURL(n),h=n;if(!m(p)&&s&&s.currentSrc&&(h=s.currentSrc,p=l.resourceForURL(h)),!p||!m(p))return null;const k=p,L=p.displayName,f=p.content?p.content:p.url.split("base64,")[1],b=p.contentSize(),C=b||i.StringUtilities.base64ToSize(f),w=C>0?i.NumberUtilities.bytesToString(C):"";return new Promise((e=>{const n=document.createElement("img");n.addEventListener("load",(function(){const o=document.createElement("div"),a=o.attachShadow({mode:"open"});a.adoptedStyleSheets=[d];const c=a.createChild("table");c.className="image-preview-container";const l=c.createChild("tr").createChild("td","image-container");l.colSpan=2;const p=l.createChild("div");p.title=L,p.appendChild(n),p.addEventListener("click",(()=>{t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(h)}));const m=n.naturalWidth,k=n.naturalHeight,f=s?s.renderedWidth:m,b=s?s.renderedHeight:k;if(r){const e=c.createChild("tr","row");e.createChild("td","title").textContent=g(u.renderedSize),e.createChild("td","description").textContent=`${f} × ${b} px`;const t=c.createChild("tr","row");if(t.createChild("td","title").textContent=g(u.renderedAspectRatio),t.createChild("td","description").textContent=i.NumberUtilities.aspectRatio(f,b),b!==k||f!==m){const e=c.createChild("tr","row");e.createChild("td","title").textContent=g(u.intrinsicSize),e.createChild("td","description").textContent=`${m} × ${k} px`;const t=c.createChild("tr","row");t.createChild("td","title").textContent=g(u.intrinsicAspectRatio),t.createChild("td","description").textContent=i.NumberUtilities.aspectRatio(m,k)}}const C=c.createChild("tr","row");C.createChild("td","title").textContent=g(u.fileSize),C.createChild("td","description").textContent=w;const v=c.createChild("tr","row");v.createChild("td","title").textContent=g(u.currentSource);const S=i.StringUtilities.trimMiddle(h,100),I=v.createChild("td","description description-link").createChild("span","source-link");I.textContent=S,I.addEventListener("click",(()=>{t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(h)})),e(o)}),!1),n.addEventListener("error",(()=>e(null)),!1),c&&(n.alt=c),k.populateImageSource(n)}))}static async loadDimensionsForNode(e){if(!e.nodeName()||"img"!==e.nodeName().toLowerCase())return;const t=await e.resolveToObject("");if(!t)return;const n=await t.callFunctionJSON((function(){return{renderedWidth:this.width,renderedHeight:this.height,currentSrc:this.currentSrc}}),void 0);return t.release(),n}static defaultAltTextForImageURL(t){const n=new e.ParsedURL.ParsedURL(t),i=n.isValid?n.displayName:g(u.unknownSource);return g(u.imageFromS,{PH1:i})}}});const k={unknown:"(unknown)",auto:"auto",revealInS:"Reveal in {PH1}",reveal:"Reveal",openUsingS:"Open using {PH1}",linkHandling:"Link handling:"},L=n.i18n.registerUIStrings("ui/legacy/components/utils/Linkifier.ts",k),f=n.i18n.getLocalizedString.bind(void 0,L),b=new Set;let C=null;const w=new WeakMap,v=new WeakMap,S=new WeakMap,I=new Map;let y;class x{maxLength;anchorsByTarget;locationPoolByTarget;onLiveLocationUpdate;useLinkDecorator;constructor(e,t,n=(()=>{})){this.maxLength=e||a.UIUtils.MaxLengthForDisplayedURLs,this.anchorsByTarget=new Map,this.locationPoolByTarget=new Map,this.onLiveLocationUpdate=n,this.useLinkDecorator=Boolean(t),b.add(this),o.TargetManager.TargetManager.instance().observeTargets(this)}static setLinkDecorator(e){console.assert(!C,"Cannot re-register link decorator."),C=e,e.addEventListener(T.Events.LinkIconChanged,(function(e){const t=e.data,n=w.get(t)||[];for(const e of n)x.updateLinkDecorations(e)}));for(const e of b)e.updateAllAnchorDecorations()}updateAllAnchorDecorations(){for(const e of this.anchorsByTarget.values())for(const t of e)x.updateLinkDecorations(t)}static bindUILocation(e,t){const n=x.linkInfo(e);if(!n)return;if(n.uiLocation=t,!t)return;const i=t.uiSourceCode;let o=w.get(i);o||(o=new Set,w.set(i,o)),o.add(e)}static unbindUILocation(e){const t=x.linkInfo(e);if(!t||!t.uiLocation)return;const n=t.uiLocation.uiSourceCode;t.uiLocation=null;const i=w.get(n);i&&i.delete(e)}static bindBreakpoint(e,t){const n=x.linkInfo(e);if(!n)return;const i=s.BreakpointManager.BreakpointManager.instance().findBreakpoint(t);i&&(n.revealable=i)}static unbindBreakpoint(e){const t=x.linkInfo(e);t&&t.revealable&&(t.revealable=null)}targetAdded(e){this.anchorsByTarget.set(e,[]),this.locationPoolByTarget.set(e,new r.LiveLocation.LiveLocationPool)}targetRemoved(e){const t=this.locationPoolByTarget.get(e);if(this.locationPoolByTarget.delete(e),!t)return;t.disposeAll();const n=this.anchorsByTarget.get(e);if(n){this.anchorsByTarget.delete(e);for(const e of n){const t=x.linkInfo(e);if(!t)continue;t.liveLocation=null,x.unbindUILocation(e);const n=t.fallback;n&&e.replaceWith(n)}}}maybeLinkifyScriptLocation(e,t,n,i,a){let s=null;const c={lineNumber:i,maxLength:this.maxLength,columnNumber:a?.columnNumber,showColumnNumber:Boolean(a?.showColumnNumber),className:a?.className,tabStop:a?.tabStop,inlineFrameIndex:a?.inlineFrameIndex??0,userMetric:a?.userMetric},{columnNumber:l,className:d=""}=c;if(n&&(s=x.linkifyURL(n,c)),!e||e.isDisposed())return s;const u=e.model(o.DebuggerModel.DebuggerModel);if(!u)return s;const p=t?u.createRawLocationByScriptId(t,i||0,l,c.inlineFrameIndex):u.createRawLocationByURL(n,i||0,l,c.inlineFrameIndex);if(!p)return s;const g={tabStop:a?.tabStop},{link:m,linkInfo:h}=x.createLink(s&&s.textContent?s.textContent:"",d,g);h.enableDecorator=this.useLinkDecorator,h.fallback=s,h.userMetric=a?.userMetric;const k=this.locationPoolByTarget.get(p.debuggerModel.target());if(!k)return s;const L={showColumnNumber:c.showColumnNumber,revealBreakpoint:a?.revealBreakpoint},f=this.onLiveLocationUpdate;r.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().createLiveLocation(p,this.updateAnchor.bind(this,m,L),k).then((e=>{e&&(h.liveLocation=e,f())}));return this.anchorsByTarget.get(p.debuggerModel.target()).push(m),m}linkifyScriptLocation(e,t,n,i,o){const r=this.maybeLinkifyScriptLocation(e,t,n,i,o),a={lineNumber:i,maxLength:this.maxLength,className:o?.className,columnNumber:o?.columnNumber,showColumnNumber:Boolean(o?.showColumnNumber),inlineFrameIndex:o?.inlineFrameIndex??0,tabStop:o?.tabStop,userMetric:o?.userMetric};return r||x.linkifyURL(n,a)}linkifyRawLocation(e,t,n){return this.linkifyScriptLocation(e.debuggerModel.target(),e.scriptId,t,e.lineNumber,{columnNumber:e.columnNumber,className:n,inlineFrameIndex:e.inlineFrameIndex})}maybeLinkifyConsoleCallFrame(e,t,n){const i={...n,columnNumber:t.columnNumber,inlineFrameIndex:n?.inlineFrameIndex??0};return this.maybeLinkifyScriptLocation(e,t.scriptId,t.url,t.lineNumber,i)}linkifyStackTraceTopFrame(e,t){console.assert(t.callFrames.length>0);const{url:n,lineNumber:i,columnNumber:a}=t.callFrames[0],s=x.linkifyURL(n,{lineNumber:i,columnNumber:a,showColumnNumber:!1,inlineFrameIndex:0,maxLength:this.maxLength,preventClick:!0});if(!e)return s;const c=this.locationPoolByTarget.get(e);if(!c)return console.assert(e.isDisposed()),s;console.assert(!e.isDisposed());const l=e.model(o.DebuggerModel.DebuggerModel),{link:d,linkInfo:u}=x.createLink("","");u.enableDecorator=this.useLinkDecorator,u.fallback=s;const p=this.onLiveLocationUpdate;r.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().createStackTraceTopFrameLiveLocation(l.createRawLocationsByStackTrace(t),this.updateAnchor.bind(this,d,{showColumnNumber:!1}),c).then((e=>{u.liveLocation=e,p()}));return this.anchorsByTarget.get(e).push(d),d}linkifyCSSLocation(e,t){const{link:n,linkInfo:i}=x.createLink("",t||"",{tabStop:!0});i.enableDecorator=this.useLinkDecorator;const o=this.locationPoolByTarget.get(e.cssModel().target());if(!o)return n;const a=this.onLiveLocationUpdate;r.CSSWorkspaceBinding.CSSWorkspaceBinding.instance().createLiveLocation(e,this.updateAnchor.bind(this,n,{showColumnNumber:!1}),o).then((e=>{i.liveLocation=e,a()}));return this.anchorsByTarget.get(e.cssModel().target()).push(n),n}reset(){for(const e of[...this.anchorsByTarget.keys()])this.targetRemoved(e),this.targetAdded(e)}dispose(){for(const e of[...this.anchorsByTarget.keys()])this.targetRemoved(e);o.TargetManager.TargetManager.instance().unobserveTargets(this),b.delete(this)}async updateAnchor(t,n,i){x.unbindUILocation(t),n.revealBreakpoint&&x.unbindBreakpoint(t);const o=await i.uiLocation();if(!o){if(i instanceof r.CSSWorkspaceBinding.LiveLocation){const n=i.header();n&&n.ownerNode&&(t.addEventListener("click",(t=>{t.consume(!0),e.Revealer.reveal(n.ownerNode||null)}),!1),x.setTrimmedText(t,"<style>"))}return}x.bindUILocation(t,o),n.revealBreakpoint&&x.bindBreakpoint(t,o);const s=o.linkText(!0,n.showColumnNumber);x.setTrimmedText(t,s,this.maxLength);let c=o.uiSourceCode.url();"application/wasm"===o.uiSourceCode.mimeType()?"number"==typeof o.columnNumber&&(c+=`:0x${o.columnNumber.toString(16)}`):(c+=":"+(o.lineNumber+1),n.showColumnNumber&&"number"==typeof o.columnNumber&&(c+=":"+(o.columnNumber+1))),a.Tooltip.Tooltip.install(t,c),t.classList.toggle("ignore-list-link",await i.isIgnoreListed()),x.updateLinkDecorations(t)}setLiveLocationUpdateCallback(e){this.onLiveLocationUpdate=e}static updateLinkDecorations(e){const t=x.linkInfo(e);if(!t||!t.enableDecorator)return;if(!C||!t.uiLocation)return;t.icon&&t.icon.parentElement&&e.removeChild(t.icon);const n=C.linkIcon(t.uiLocation.uiSourceCode);n&&(n.style.setProperty("margin-right","2px"),e.insertBefore(n,e.firstChild)),t.icon=n}static linkifyURL(e,t){const n=(t=t||{showColumnNumber:!1,inlineFrameIndex:0}).text,i=t.className||"",o=t.lineNumber,s=t.columnNumber,c=t.showColumnNumber,l=t.preventClick,d=t.maxLength||a.UIUtils.MaxLengthForDisplayedURLs,u=t.bypassURLTrimming;if(!e||e.trim().toLowerCase().startsWith("javascript:")){const t=document.createElement("span");return i&&(t.className=i),t.textContent=n||e||f(k.unknown),t}let p=n||r.ResourceUtils.displayNameForURL(e);"number"!=typeof o||n||(p+=":"+(o+1),c&&"number"==typeof s&&(p+=":"+(s+1)));const g={maxLength:d,title:p!==e?e:"",href:e,preventClick:l,tabStop:t.tabStop,bypassURLTrimming:u},{link:m,linkInfo:h}=x.createLink(p,i,g);return o&&(h.lineNumber=o),s&&(h.columnNumber=s),h.userMetric=t?.userMetric,m}static linkifyRevealable(e,t,n,i,o){const r={maxLength:a.UIUtils.MaxLengthForDisplayedURLs,href:n,title:i},{link:s,linkInfo:c}=x.createLink(t,o||"",r);return c.revealable=e,s}static createLink(e,t,n={}){const{maxLength:i,title:o,href:r,preventClick:s,tabStop:c,bypassURLTrimming:l}=n,d=document.createElement("span");t&&(d.className=t),d.classList.add("devtools-link"),o&&a.Tooltip.Tooltip.install(d,o),r&&(d.href=r),e instanceof HTMLElement?d.appendChild(e):l?(d.classList.add("devtools-link-styled-trim"),x.appendTextWithoutHashes(d,e)):x.setTrimmedText(d,e,i);const u={icon:null,enableDecorator:!1,uiLocation:null,liveLocation:null,url:r||null,lineNumber:null,columnNumber:null,inlineFrameIndex:0,revealable:null,fallback:null};return v.set(d,u),s?d.classList.add("devtools-link-prevent-click"):(d.addEventListener("click",(e=>{x.handleClick(e)&&e.consume(!0)}),!1),d.addEventListener("keydown",(e=>{"Enter"===e.key&&x.handleClick(e)&&e.consume(!0)}),!1)),a.ARIAUtils.markAsLink(d),d.tabIndex=c?0:-1,{link:d,linkInfo:u}}static setTrimmedText(e,t,n){if(e.removeChildren(),n&&t.length>n){const i=function(e,t){let n=Math.floor(t/2),i=e.length-Math.ceil(t/2)+1;const o=e.codePointAt(i-1);void 0!==o&&o>=65536&&(i++,n++);const r=e.codePointAt(n-1);void 0!==r&&n>0&&r>=65536&&n--;return[e.substring(0,n),e.substring(n,i),e.substring(i)]}(t,n);x.appendTextWithoutHashes(e,i[0]),x.appendHiddenText(e,i[1]),x.appendTextWithoutHashes(e,i[2])}else x.appendTextWithoutHashes(e,t)}static appendTextWithoutHashes(e,t){const n=c.TextUtils.Utils.splitStringByRegexes(t,[/[a-f0-9]{20,}/g]);for(const t of n)-1===t.regexIndex?a.UIUtils.createTextChild(e,t.value):(a.UIUtils.createTextChild(e,t.value.substring(0,7)),x.appendHiddenText(e,t.value.substring(7)))}static appendHiddenText(e,t){const n=a.UIUtils.createTextChild(e.createChild("span","devtools-link-ellipsis"),"…");S.set(n,t)}static untruncatedNodeText(e){return S.get(e)||e.textContent||""}static linkInfo(e){return e&&v.get(e)||null}static handleClick(e){const t=e.currentTarget;if(a.UIUtils.isBeingEdited(e.target)||t.hasSelection())return!1;const n=x.linkInfo(t);return!!n&&x.invokeFirstAction(n)}static handleClickFromNewComponentLand(e){x.invokeFirstAction(e)}static invokeFirstAction(e){const n=x.linkActions(e);return!!n.length&&(n[0].handler.call(null),e.userMetric&&t.userMetrics.actionTaken(e.userMetric),!0)}static linkHandlerSetting(){return y||(y=e.Settings.Settings.instance().createSetting("openLinkHandler",f(k.auto))),y}static registerLinkHandler(e,t){I.set(e,t),F.instance().update()}static unregisterLinkHandler(e){I.delete(e),F.instance().update()}static uiLocation(e){const t=x.linkInfo(e);return t?t.uiLocation:null}static linkActions(n){const o=[];if(!n)return o;let c=i.DevToolsPath.EmptyUrlString,d=null;if(n.uiLocation)d=n.uiLocation,c=d.uiSourceCode.contentURL();else if(n.url){c=n.url;const t=l.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(c)||l.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(e.ParsedURL.ParsedURL.urlWithoutHash(c));d=t?t.uiLocation(n.lineNumber||0,n.columnNumber||0):null}const u=c?r.ResourceUtils.resourceForURL(c):null,p=d?d.uiSourceCode:u,g=n.revealable||d||u;if(g){const n=e.Revealer.revealDestination(g);o.push({section:"reveal",title:n?f(k.revealInS,{PH1:n}):f(k.reveal),handler:()=>(g instanceof s.BreakpointManager.BreakpointLocation&&t.userMetrics.breakpointEditDialogRevealedFrom(5),e.Revealer.reveal(g))})}if(p){const e=d?d.lineNumber:n.lineNumber||0;for(const t of I.keys()){const n=I.get(t);if(!n)continue;const i={section:"reveal",title:f(k.openUsingS,{PH1:t}),handler:n.bind(null,p,e)};t===x.linkHandlerSetting().get()?o.unshift(i):o.push(i)}}if((u||n.url)&&(o.push({section:"reveal",title:a.UIUtils.openLinkExternallyLabel(),handler:()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(c)}),o.push({section:"clipboard",title:a.UIUtils.copyLinkAddressLabel(),handler:()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(c)})),d&&d.uiSourceCode){const e=d.uiSourceCode;o.push({section:"clipboard",title:a.UIUtils.copyFileNameLabel(),handler:()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(e.displayName())})}return o}}var T;let U,N;!function(e){let t;!function(e){e.LinkIconChanged="LinkIconChanged"}(t=e.Events||(e.Events={}))}(T||(T={}));class D{static instance(e={forceNew:null}){const{forceNew:t}=e;return U&&!t||(U=new D),U}appendApplicableItems(e,t,n){let i=n;for(;i&&!v.get(i);)i=i.parentNodeOrShadowHost();const o=i,r=x.linkInfo(o);if(!r)return;const a=x.linkActions(r);for(const e of a)t.section(e.section).appendItem(e.title,e.handler)}}class F{element;constructor(){this.element=document.createElement("select"),this.element.classList.add("chrome-select"),this.element.addEventListener("change",this.onChange.bind(this),!1),this.update()}static instance(e={forceNew:null}){const{forceNew:t}=e;return N&&!t||(N=new F),N}update(){this.element.removeChildren();const e=[...I.keys()];e.unshift(f(k.auto));for(const t of e){const e=document.createElement("option");e.textContent=t,e.selected=t===x.linkHandlerSetting().get(),this.element.appendChild(e)}this.element.disabled=e.length<=1}onChange(e){if(!e.target)return;const t=e.target.value;x.linkHandlerSetting().set(t)}settingElement(){return a.SettingsUI.createCustomSetting(f(k.linkHandling),this.element)}}let R,M=!1;M||(M=!0,window.addEventListener("linkifieractivated",(function(e){const t=e;x.handleClickFromNewComponentLand(t.data)})));class H{static instance(e={forceNew:null}){const{forceNew:t}=e;return R&&!t||(R=new H),R}appendApplicableItems(n,i,r){const s=r,c=s.contentURL();if(c){c.startsWith("file://")||i.revealSection().appendItem(a.UIUtils.openLinkExternallyLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(c.endsWith(":formatted")?e.ParsedURL.ParsedURL.slice(c,0,c.lastIndexOf(":")):c)));for(const e of I.keys()){const t=I.get(e);t&&i.revealSection().appendItem(f(k.openUsingS,{PH1:e}),t.bind(null,s,0))}s instanceof o.NetworkRequest.NetworkRequest||(i.clipboardSection().appendItem(a.UIUtils.copyLinkAddressLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(c))),i.clipboardSection().appendItem(a.UIUtils.copyFileNameLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(s.displayName()))))}}}var B=Object.freeze({__proto__:null,Linkifier:x,get LinkDecorator(){return T},LinkContextMenuProvider:D,LinkHandlerSettingUI:F,ContentProviderContextMenuProvider:H});const A=new CSSStyleSheet;A.replaceSync(":host{display:inline}.stack-preview-async-description{padding:3px 0 1px;font-style:italic}.stack-preview-container .ignore-list-link{opacity:60%}.stack-preview-container > tr{height:16px;line-height:16px}.stack-preview-container td{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding-inline:2px}.stack-preview-container .function-name{max-width:80em}.stack-preview-container:not(.show-hidden-rows) > tr.hidden-row{display:none}.stack-preview-container > tr.show-all-link,\n.stack-preview-container > tr.show-less-link{font-style:italic}.stack-preview-container.show-hidden-rows > tr.show-all-link{display:none}.stack-preview-container:not(.show-hidden-rows) > tr.show-less-link{display:none}\n/*# sourceURL=jsUtils.css */\n");const P={removeFromIgnore:"Remove from ignore list",addToIgnore:"Add script to ignore list",showSMoreFrames:"{n, plural, =1 {Show # more frame} other {Show # more frames}}",showLess:"Show less",unknownSource:"unknown"},E=n.i18n.registerUIStrings("ui/legacy/components/utils/JSPresentationUtils.ts",P),W=n.i18n.getLocalizedString.bind(void 0,E);function _(e,t){const n=new a.ContextMenu.ContextMenu(t);t.consume(!0);const i=x.uiLocation(e);i&&r.IgnoreListManager.IgnoreListManager.instance().canIgnoreListUISourceCode(i.uiSourceCode)&&(r.IgnoreListManager.IgnoreListManager.instance().isUserIgnoreListedURL(i.uiSourceCode.url())?n.debugSection().appendItem(W(P.removeFromIgnore),(()=>r.IgnoreListManager.IgnoreListManager.instance().unIgnoreListUISourceCode(i.uiSourceCode))):n.debugSection().appendItem(W(P.addToIgnore),(()=>r.IgnoreListManager.IgnoreListManager.instance().ignoreListUISourceCode(i.uiSourceCode)))),n.appendApplicableItems(t),n.show()}function z(t,n,i,s,c){const l=[];if(c){const t=new e.Throttler.Throttler(100);i.setLiveLocationUpdateCallback((()=>t.schedule((async()=>function(e,t){let n=0,i=t.length;for(let e=t.length-1;e>=0;e--){const o=t[e];if("link"in o&&o.link){const e=x.uiLocation(o.link);e&&r.IgnoreListManager.IgnoreListManager.instance().isUserOrSourceMapIgnoreListedUISourceCode(e.uiSourceCode)&&(o.ignoreListHide=!0),o.ignoreListHide&&n++}"asyncDescription"in o&&(n>0&&n===i-e-1&&(o.ignoreListHide=!0),i=e,n=0)}e(t)}(c,l)))))}function d(e,t){let c=null;t&&(c={asyncDescription:a.UIUtils.asyncStackTraceLabel(e.description,t),ignoreListHide:!1},l.push(c));let d=0,u=!1;for(const t of e.callFrames){let e=!1;const c=a.UIUtils.beautifyFunctionName(t.functionName),p=i.maybeLinkifyConsoleCallFrame(n,t,{tabStop:Boolean(s),inlineFrameIndex:0,revealBreakpoint:u});if(p){p.addEventListener("contextmenu",_.bind(null,p));const t=x.uiLocation(p);t&&r.IgnoreListManager.IgnoreListManager.instance().isUserOrSourceMapIgnoreListedUISourceCode(t.uiSourceCode)&&(e=!0),p.textContent||(p.textContent=W(P.unknownSource))}e&&++d,l.push({functionName:c,link:p,ignoreListHide:e}),u=[o.DebuggerModel.COND_BREAKPOINT_SOURCE_URL,o.DebuggerModel.LOGPOINT_SOURCE_URL].includes(t.url)}c&&d>0&&d===e.callFrames.length&&(c.ignoreListHide=!0)}d(t);let u=t.callFrames;for(let e=t.parent;e;e=e.parent)e.callFrames.length&&d(e,u),u=e.callFrames;return l}function j(e,t){e.removeChildren();let n=0;const i=[];for(const o of t){const t=e.createChild("tr");"asyncDescription"in o?(t.createChild("td").textContent="\n",t.createChild("td","stack-preview-async-description").textContent=o.asyncDescription,t.createChild("td"),t.createChild("td")):(t.createChild("td").textContent="\n",t.createChild("td","function-name").textContent=o.functionName,t.createChild("td").textContent=" @ ",o.link&&(t.createChild("td").appendChild(o.link),i.push(o.link)),o.ignoreListHide&&++n),o.ignoreListHide&&t.classList.add("hidden-row"),e.appendChild(t)}if(n){const t=e.createChild("tr","show-all-link");t.createChild("td").textContent="\n";const i=t.createChild("td");i.colSpan=4;const o=i.createChild("span","link");o.textContent=W(P.showSMoreFrames,{n:n}),o.addEventListener("click",(()=>{e.classList.add("show-hidden-rows")}),!1);const r=e.createChild("tr","show-less-link");r.createChild("td").textContent="\n";const a=r.createChild("td");a.colSpan=4;const s=a.createChild("span","link");s.textContent=W(P.showLess),s.addEventListener("click",(()=>{e.classList.remove("show-hidden-rows")}),!1)}return i}var O=Object.freeze({__proto__:null,buildStackTraceRows:z,buildStackTracePreviewContents:function(e,t,n={stackTrace:void 0,tabStops:void 0}){const{stackTrace:i,tabStops:o}=n,r=document.createElement("span");r.classList.add("monospace"),r.style.display="inline-block";const s=a.Utils.createShadowRootWithCoreStyles(r,{cssFile:[A],delegatesFocus:void 0}).createChild("table","stack-preview-container");if(!i)return{element:r,links:[]};const c=j.bind(null,s);return{element:r,links:j(s,z(i,e,t,o,c))}}});var K=Object.freeze({__proto__:null,reload:function(){a.DockController.DockController.instance().canDock()&&"undocked"===a.DockController.DockController.instance().dockSide()&&t.InspectorFrontendHost.InspectorFrontendHostInstance.setIsDocked(!0,(function(){})),t.InspectorFrontendHost.InspectorFrontendHostInstance.reattach((()=>window.location.reload()))}});const $={websocketDisconnected:"WebSocket disconnected"},q=n.i18n.registerUIStrings("ui/legacy/components/utils/TargetDetachedDialog.ts",$),J=n.i18n.getLocalizedString.bind(void 0,q);class G extends o.SDKModel.SDKModel{static hideCrashedDialog;constructor(e){super(e),e.registerInspectorDispatcher(this),e.inspectorAgent().invoke_enable(),e.parentTarget()?.type()===o.Target.Type.Browser&&G.hideCrashedDialog&&(G.hideCrashedDialog.call(null),G.hideCrashedDialog=null)}detached({reason:e}){a.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(e)}static webSocketConnectionLost(){a.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(J($.websocketDisconnected))}targetCrashed(){if(G.hideCrashedDialog)return;const e=this.target().parentTarget();if(e&&e.type()!==o.Target.Type.Browser)return;const t=new a.Dialog.Dialog;t.setSizeBehavior("MeasureContent"),t.addCloseButton(),t.setDimmed(!0),G.hideCrashedDialog=t.hide.bind(t),new a.TargetCrashedScreen.TargetCrashedScreen((()=>{G.hideCrashedDialog=null})).show(t.contentElement),t.show()}targetReloadedAfterCrash(){this.target().runtimeAgent().invoke_runIfWaitingForDebugger(),G.hideCrashedDialog&&(G.hideCrashedDialog.call(null),G.hideCrashedDialog=null)}}o.SDKModel.SDKModel.register(G,{capabilities:o.Target.Capability.Inspector,autostart:!0});var V=Object.freeze({__proto__:null,TargetDetachedDialog:G});export{h as ImagePreview,O as JSPresentationUtils,B as Linkifier,K as Reload,V as TargetDetachedDialog};
